﻿<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>aaa</title>
<style type="text/css">
body{
margin: 0;
overflow: hidden;
background: #fff;
}
#map{
position: relative;
height: 520px;
border:1px solid #3473b7;
}
#toolbar{
position: relative;
height: 33px;
padding-top:5;
}
</style>


    <script src="/Common/js/SuperMap/libs/SuperMap.Include.js"></script>
    <script src="/Common/js/SuperMap/my_superMap.js"></script>
    <script src="/Common/js/6cweb/LoadPubFile_base.js" type="text/javascript"></script>


    <script src="js/BMap_super.js"></script>

<script src='../libs/SuperMap.Include.js'></script>
<script type="text/javascript">
    var host = document.location.toString().match(/file:\/\//) ? "http://192.168.1.130:8091/" : 'http://' + document.location.host;
var map, layer, routeObj, vectorLayer, drawPoint, pointLayer, snap01,modifyFeature,
lineStyle = {
strokeColor:"red",
strokeWidth:2,
pointRadius:3,
pointerEvents:"visiblePainted",
fill:false
},
pointStyle = {
fillColor:'#669933',
fillOpacity:0.8,
pointRadius:5,
strokeColor:'#aaee77',
strokeWidth:3
},
url1 = host + "/iserver/services/map-changchun/rest/maps/China",
url2=host+"/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst";
function init(){
layer = new SuperMap.Layer.TiledDynamicRESTLayer("changchun", url1, { transparent:true, cacheEnabled:true }, { maxResolution:"auto" });
vectorLayer = new SuperMap.Layer.Vector("RouteLayer");
pointLayer = new SuperMap.Layer.Vector("pointLayer");

snap01=new SuperMap.Snap([vectorLayer,pointLayer],20,20,{actived:true}); //����activedΪtrue��ʱ�򣬲�׽�Ѽ��


drawPoint = new SuperMap.Control.DrawFeature(pointLayer, SuperMap.Handler.Point);
drawPoint.events.on({"featureadded":drawPointCompleted});
drawPoint.snap=snap01;

layer.events.on({"layerInitialized":addLayer});

map = new SuperMap.Map("map", {allOverlays:true, controls:[
new SuperMap.Control.LayerSwitcher(),
new SuperMap.Control.ScaleLine(),
new SuperMap.Control.Zoom(),
new SuperMap.Control.Navigation({
dragPanOptions:{
enableKinetic:true
}}), drawPoint]
});

}

function addLayer() {
map.addLayers([layer, vectorLayer, pointLayer]);
map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 1);
}

//ͨ��SQL��ѯ·�ɶ���
function CreateRouteObj() {
var queryParam, queryBySQLParams, queryBySQLService;
queryParam = new SuperMap.REST.FilterParameter({
name:"RouteDT_road@Changchun",
attributeFilter:"RouteID=1690"
});
queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
queryParams:[queryParam]
});
queryBySQLService = new SuperMap.REST.QueryBySQLService(url1, {
eventListeners:{
"processCompleted":processCompleted,
"processFailed":processFailed
}
});
queryBySQLService.processAsync(queryBySQLParams);
}

//·�ɶ����ѯ�ɹ�����ʼ��routeObj��ֵ��ͬʱ����ѯ��������ڵ�ͼ��
function processCompleted(queryEventArgs) {

routeObj = geo = queryEventArgs.result.recordsets[0].features[0].geometry;
var feature = new SuperMap.Feature.Vector();
feature.geometry = geo;
feature.style = lineStyle;
vectorLayer.addFeatures(feature);
alert("��ѯ�ɹ�");
}

//·�ɶ����ѯʧ�ܣ���ʾ��ʾ��Ϣ
function processFailed() {
alert("��ѯʧ��");
}

//�����ؼ����ж�routeObj�Ƿ�Ϊ�գ����Ϊ�����ֹ��һ������
function RouteCalculateMeasure() {
if (!routeObj) {
alert("��ͨ����ѯ��ȡ·�ɶ���");
return;
}
drawPoint.activate();
}
//���Ƶ���ɴ����¼����Ƚ�������ڵ�ͼ�ϣ�Ȼ���Ե��geometry�Ͳ�ѯ���
// routeObjΪ������ʼ��"�㶨���"�Ĳ����ࡣ
function drawPointCompleted(drawGeometryArgs) {
var feature = new SuperMap.Feature.Vector();
var geometry = drawGeometryArgs.feature.geometry
feature.geometry = geometry;
feature.style = pointStyle;
pointLayer.addFeatures(feature);

//�������㶨��̡������ࡣ
var parameters = new SuperMap.REST.RouteCalculateMeasureParameters({
"sourceRoute":routeObj,
"tolerance":10,
"point":geometry,
"isIgnoreGap":false
});

//�������㶨��̡������ࡣ
var routeCalculateMeasureService = new SuperMap.REST.RouteCalculateMeasureService(url2, {
eventListeners:{
"processCompleted":routeCalculateMeasureCompleted,
'processFailed':routeCalculateMeasureFailed
}
}
);
//ִ����ز���
routeCalculateMeasureService.processAsync(parameters);
}

//���㶨��̡���ѯ��ɣ���ʾ������Ϣ
function routeCalculateMeasureCompleted(e) {
alert("��ѯ��ȡ��MֵΪ��" + e.result.measure);
}

//���㶨��̡���ѯʧ�ܣ���ʾ����˷��ص���Ϣ
function routeCalculateMeasureFailed(e) {
alert(e.error.errorMsg);
}

//�Ƴ�ͼ��Ҫ�أ���ʹ����ؼ�ʧЧ��ͬʱ��·�ɶ����ÿգ�ȥ����ʾ��Ϣ
function Remove() {
vectorLayer.removeAllFeatures();
pointLayer.removeAllFeatures();
drawPoint.deactivate();
routeObj = null;
}
</script>
</head>
<body onload="init()">
<div id="toolbar">
<input type="button" value="��ѯ·�ɶ���" onclick="CreateRouteObj()" />
<input type="button" value="ָ����ѯ��" onclick="RouteCalculateMeasure()" />
<input type="button" value="���" onclick="Remove()" />
</div>
<div id="map"></div>
</body>
</html>